import { CHANNEL_SAVE_LIST, CHANNEL_UPDATE_ID } from '../action/actionType';

const initialState = {
  channelList: [],
  currentId: 0,
};

// 命名 模块Reducer
export default function channelReducer(
  state = initialState,
  { type, payload }
) {
  switch (type) {
    // 3. reducer 中完成计算
    case CHANNEL_SAVE_LIST:
      return {
        ...state,
        channelList: payload,
      };
    // 完成更新 currentId 的计算
    case CHANNEL_UPDATE_ID:
      return {
        ...state,
        currentId: payload,
      };
    default:
      return state;
  }
}
